<?php
$dbhost = 'localhost';  // mysql服务器主机地址
$dbuser = 'ether_gq';            // mysql用户名
$dbpass = '8MN6ZYmayNbRwxm7';          // mysql用户名密码
$dbname = 'ether_gq';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);


function delete_friend($username,$friendname){
    global $conn;

    $a='SELECT * FROM user WHERE username='."'".$friendname."'";
    $sql=mysqli_query($conn,$a);

    $row = mysqli_fetch_array($sql);

    $friends_list=$row[3];
    $friends_list=json_decode($friends_list,true);

    $key = array_search($username,$friends_list['friends']);
    if(!($key === false)){
        unset($friends_list['friends'][$key]);
    };

    $friends_list=json_encode($friends_list);

    $a='UPDATE user SET friends=\''.$friends_list.'\' WHERE username=\''.$friendname.'\'';
    
    if(mysqli_query($conn,$a)){
        echo '1';
    };
};

delete_friend($_GET['username'],$_GET['friendname']);
delete_friend($_GET['friendname'],$_GET['username']);


mysqli_close($conn);


?>